package com.bwie.servicemodule.base;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.bwie.servicemodule.R;
import com.bwie.servicemodule.controler.OkGoControler;
import com.bwie.servicemodule.controler.StatuesBarControler;

import okhttp3.OkHttpClient;

/**
 * 应用activity父类
 * ->封装与界面相关内容
 * */
public abstract class BaseActivity extends AppCompatActivity implements OkGoControler.HttpListener {

    protected SharedPreferences preferences;
    protected SharedPreferences.Editor editor;
    protected OkGoControler okGoControler;
    protected String uri = "http://api.yunzhancn.cn/api/app.interface.php?siteid=78703&";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layoutID());
        StatuesBarControler.setStatusBarColor(
                this,getResources().getColor(R.color.colorAccent));

        preferences = getSharedPreferences( "jiancai", MODE_PRIVATE );
        editor = preferences.edit();
        okGoControler = new OkGoControler();
        okGoControler.setListener( this );
        init();
    }

    /**
     * msg:关联XML方法
     * */
    protected abstract int layoutID();
    /**
     * msg:初始化控件方法
     * */
    protected abstract void init();

    /**
     * msg:查找控件方法
     * */
    public <T extends View>T f(int id){
        T t = findViewById(id);
        return t;
    }

    /**
     * msg:界面跳转方法
     * */
     public void startUI(Class clazz){
         Intent intent = new Intent(this,clazz);
         startActivity(intent);
     }
    /**
     * msg:界面跳转方法
     * */
    public void startUI_Finish(Class clazz){
        Intent intent = new Intent(this,clazz);
        startActivity(intent);
        finish();
    }
    /**
     * msg:界面跳转方法
     * */
    public void startUI(Intent intent){
        startActivity(intent);
    }
    /**
     * msg:界面跳转方法
     * */
    public void startUI_Finish(Intent intent){
        startActivity(intent);
    }


    @Override
    public void onSuccess(String url, String result) {

    }

    @Override
    public void onSuccess(String url, String result, int type) {

    }

    @Override
    public void onErro(String url, String msg) {

    }
}
